package org.planaz.campusvoting.controller;

import jakarta.annotation.Resource;
import org.planaz.campusvoting.common.result.Result;
import org.planaz.campusvoting.common.result.Results;
import org.planaz.campusvoting.pojo.Activity;
import org.planaz.campusvoting.pojo.ActivityFilter;
import org.planaz.campusvoting.pojo.Item;
import org.planaz.campusvoting.pojo.ItemFilter;
import org.planaz.campusvoting.service.ActivityService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/api/v1/activity")
public class ActivityController {

    @Resource
    private ActivityService activityService;

    @RequestMapping("/publish")
    public Result<?> publish(@RequestBody ActivityFilter activity){
        return activityService.publish(activity);
    }
    @RequestMapping ("/list")
    public Result<?> list(@RequestBody ActivityFilter activityFilter){
        return activityService.list(activityFilter);
    }
    @RequestMapping ("/mylist")
    public Result<?> mylist(@RequestBody Activity activity){
        return activityService.mylist(activity);
    }

    @RequestMapping("/modify/activity")
    public Result<?> modify(@RequestBody Activity activity){
        return activityService.modify(activity);
    }
    @RequestMapping("/add")
    public Result<?> add(@RequestBody Item item){
        return activityService.add(item);
    }
    @RequestMapping("/all")
    public Result<?> all(@RequestBody ItemFilter itemFilter){
        return activityService.all(itemFilter);
    }
    @RequestMapping("/vote")
    public Result<?> like(@RequestParam Long id){
        return activityService.like(id);
    }
    @RequestMapping("/unvote")
    public Result<?> unlike(@RequestParam Long id){
        return activityService.unlike(id);
    }
    @RequestMapping("/modify/candidate")
    public Result<?> modifyCandidate(@RequestBody Item item){
        return activityService.modifyCandidate(item);
    }
    @RequestMapping("/audit/approve")
    public Result<?> approve(Long id){
        Item item = new Item();
        item.setId(id);
        item.setState("approved");
        return activityService.modifyCandidate(item);
    }
    @RequestMapping("/audit/reject")
    public Result<?> reject(Long id,String cause){
        Item item = new Item();
        item.setId(id);
        item.setCause(cause);
        item.setState("rejected");
        return activityService.modifyCandidate(item);
    }
    @RequestMapping("/delete/activity")
    public Result<?> deleteA(@RequestParam Long id){
        return activityService.deleteA(id);
    }
    @RequestMapping("/delete/candidate")
    public Result<?> deleteI(@RequestParam Long id){
        return activityService.deleteI(id);
    }

    //查看我投票过的活动和报名过的活动
    @RequestMapping("/myvote")
    public Result<?> myVote(@RequestParam(required = false) Long id){
        return activityService.myVote(id);
    }
    @RequestMapping("/myenter")
    public Result<?> myEnter(@RequestParam(required = false) Long id){
        return activityService.myEnter(id);
    }
    @RequestMapping("/myvote/act")
    public Result<?> myVoteAct(@RequestParam(required = false) Long id){
        return activityService.myVoteAct(id);
    }
    @RequestMapping("/detail")
    public Result<?> detail(@RequestParam Long actId){
        return activityService.activityDetail(actId);
    }
    @RequestMapping("/allvote")
    public Result<?> allVote(@RequestParam Long id){
        return activityService.allvote(id);
    }
}
